<?php

class GadgetController extends Controller
{
	public $layout='//layouts/main';
	public function init()
	{
			Yii::app()->theme = 'orange';
			parent::init();
	}
	public function actionIndex()
	{
		
		$device = Yii::app()->request->getParam('device');
		$name = Yii::app()->request->getParam('name');
		$gadget = Gadget::model()->searchProduct($device,$name);
		
		$this->render('index',array(
			'gadget'=>$gadget,
			'device'=>$device,
			'name'=>$name,
		));
	}
	public function actionSuggest()
	{
		$input = Yii::app()->request->getParam('input');
		// dump($input);
		$gadget = Gadget::model()->searchProduct(null,$input,false);
		$data = array();
		if(!empty($gadget['data'])){
			foreach($gadget['data'] as $key=>$value){
				$data[$key]['id']  = $value->id;
				$data[$key]['value']  = $value->name;
				$data[$key]['alias']  = Yii::app()->createUrl("/trade/{$value->urlKey}");
				if($value->imageUrl!=null)
					$data[$key]['image']  = "http://".$_SERVER['HTTP_HOST']."/uploads/products/fill/48-48/".$value->imageUrl;
				else
					$data[$key]['image']  = "http://".$_SERVER['HTTP_HOST']."/uploads/products/images.jpg";
				// $data[$key]['info']  = Yii::app()->baseUrl."/uploads/products/fill/32-32/".$value->imageUrl;
			}
		}
		jsonOut(array('results'=>$data));
		
	}
}